package radio.vnmedia.vn.utils.htmlparser;

public class BlockTextFinder {
	private String mText;
	private String mFrom, mTo;
	private int endIndex = 0;

	public BlockTextFinder(String text, int find_fromIndex, String from, String to) {
		mText = text;
		mFrom = from;
		mTo = to;
		fromIndex = 0;
		toIndex = 0;
		fromIndex = find_fromIndex;
	}

	private int fromIndex = 0, toIndex = 0;

	public boolean hasNext() {
		if (fromIndex == -1 || toIndex == -1)
			return false;

		fromIndex = mText.indexOf(mFrom, fromIndex);
		toIndex = mText.indexOf(mTo, fromIndex + mFrom.length());

		if (fromIndex >= 0 && toIndex >= 0 && fromIndex <= toIndex) {
			return true;
		}
		return false;
	}

	public int getEndIndex() {
		return endIndex;
	}

	public String getText() {
		String text = mText.substring(fromIndex + mFrom.length(), toIndex);
		fromIndex = toIndex + mTo.length();
		if (mText.indexOf(mFrom, fromIndex) != -1) {
			endIndex = fromIndex;
		}
		return text;
	}

}
